#include"comm.hpp"

using namespace std;

int main()
{
    int fd = open(FIFO_FILE, O_RDONLY);
    if(fd < 0)
    {
        perror("open");
        exit(FIFO_OPEN_ERR);
    }

    cout << "server open file done" << endl;

    char buffer[SIZE] = {0};
    while(1)
    {
        cout << "client say# ";
        ssize_t ret = read(fd, buffer, SIZE);
        if(ret > 0)
        {
            buffer[ret] = 0;
            cout << buffer << endl;
        }
        else if(ret == 0)
        {
            cout << "message over, exit." << endl;
            break;
        }
        else
        {
            perror("read");
            exit(FIFO_READ_ERR);
        }
    }

    close(fd);
    return 0;
}